package com.example.pdfprocessor;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.io.File;

@SpringBootApplication
public class PdfProcessorApplication {

    static {
        // 确保临时目录存在
        createDirectories();
    }
    
    /**
     * 创建必要的目录结构
     */
    private static void createDirectories() {
        try {
            // 确保文档处理器的目录存在
            String tempDirPath = System.getProperty("java.io.tmpdir");
            if (!tempDirPath.endsWith(File.separator)) {
                tempDirPath += File.separator;
            }
            tempDirPath += "document-processor";
            
            File tempDir = new File(tempDirPath);
            if (!tempDir.exists()) {
                boolean created = tempDir.mkdirs();
                if (created) {
                    System.out.println("创建临时目录: " + tempDir.getAbsolutePath());
                }
            }
            
            // 创建上传目录
            File uploadsDir = new File(tempDirPath + File.separator + "uploads");
            if (!uploadsDir.exists()) {
                boolean created = uploadsDir.mkdirs();
                if (created) {
                    System.out.println("创建上传目录: " + uploadsDir.getAbsolutePath());
                }
            }
            
            // 创建临时文件目录
            File tempFilesDir = new File(tempDirPath + File.separator + "temp");
            if (!tempFilesDir.exists()) {
                boolean created = tempFilesDir.mkdirs();
                if (created) {
                    System.out.println("创建临时文件目录: " + tempFilesDir.getAbsolutePath());
                }
            }
        } catch (Exception e) {
            System.err.println("创建目录时出错: " + e.getMessage());
        }
    }

    public static void main(String[] args) {
        SpringApplication.run(PdfProcessorApplication.class, args);
    }
} 